package com.szxy.miaosha.controller;

import com.szxy.miaosha.domain.MiaoshaUser;
import com.szxy.miaosha.domain.OrderInfo;
import com.szxy.miaosha.service.GoodsService;
import com.szxy.miaosha.service.MiaoShaService;
import com.szxy.miaosha.service.MiaoShaUserService;
import com.szxy.miaosha.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @Author: zwz
 * @Date:2020/9/6 23:10
 * @Description:com.szxy.miaosha.controller
 * @Version:1.0 商品服务控制器
 * 针对商品服务， 每次请求，都要请求 Redis 服务器，拿到对应的 token ，判断用户是否过期或者存在
 * 这样的操作，是重复性，代码看起来不是很清爽
 **/
@Controller
@RequestMapping("/miaosha")
public class MiaoShaController {

    @Autowired
    private MiaoShaService miaoShaService;

    /**
     * 前往商品列表 （改造后）
     * miaoshaUser 对象 MiaoShaUserArgumentResolver 注入
     *
     * @return
     */
    @PostMapping("/do_miaosha")
    public String toPage(
            @RequestParam("goodsId") long goodsId,
            Model model, MiaoshaUser miaoshaUser) {
        // 若用户没有登录，则返回登录界面
        if (miaoshaUser == null) {
            return "login";
        }
        miaoShaService.miaoShao(model, goodsId, miaoshaUser);
        return "order_detail";
    }


}
